package com.daxt.controller.filemanager;

import com.daxt.base.common.util.RedisUtil;
import com.daxt.common.result.Result;
import com.daxt.common.result.ResultCode;
import com.daxt.common.result.ResultUtil;
import com.daxt.mapper.archives.ArchivesDocMapper;
import com.daxt.mapper.archives.ArchivesTempletMapper;
import com.daxt.mapper.sys.UreportFileMapper;
import com.daxt.model.dic.SystemConfigType;
import com.daxt.model.service.base.vo.UreportFile;
import com.daxt.service.ArchivesService;
import com.daxt.utils.file.FileBaseUtil;
import com.google.common.base.Joiner;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: lig
 * @date: 2021/7/30
 */
@Api(tags = "报表管理")
@RestController
@RequestMapping("/report")
public class ReportController {

    @Autowired
    private ArchivesTempletMapper archivesTempletMapper;
    @Autowired
    private ArchivesDocMapper archivesDocMapper;
    @Autowired
    private ArchivesService archivesService;
    @Autowired
    private UreportFileMapper ureportFileMapper;


    @ApiOperation(value = "获取报表地址", notes = "")
    @PostMapping("/{templetId}")
    public Result<String> acquireAddresses(@PathVariable("templetId") String templetId, @RequestBody List<String> ids) {

        String resultUrl = "";
        UreportFile template = ureportFileMapper.selectById(templetId);

        String templetUrl = template.getUrl();


        if (StringUtils.isEmpty(templetUrl))
            return ResultUtil.data(ResultCode.RESULT_ERROR.getCode(), "报表地址异常，请联系系统维护人员", null);


        String strIds = Joiner.on(",").join(ids);
        String sysHome = RedisUtil.getSysConfig(SystemConfigType.SYS_HOME);
        resultUrl = sysHome + templetUrl + "&dossierIds=" + strIds + "&itemNumIds=" + strIds;

        return ResultUtil.data(ResultCode.RESULT_SUCCESS.getCode(), ResultCode.RESULT_SUCCESS.getMes(), FileBaseUtil.againstToOpinion(resultUrl));


    }

}
